<% include("../public/commonheader.html"){}%>
 <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">会员管理</a>
            <a>
              <cite>会员列表</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
 </div>

<div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5" action="${'/admin/members',url}" method="get">
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="searchby">
									  <option value="1">用户名</option>
									  <option value="2">手机</option>
									  <option value="3">邮箱</option>
									</select>
                                </div>
								<div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="keyword"  placeholder="请输入" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="Sca.open('添加会员','${'/admin/members/add',url}',600,420)"><i class="layui-icon"></i>添加会员</button>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
							<table class="layui-table layui-form">
                                <thead>
                                  <tr>
                                    <th width="64">ID</th>
                                    <th>${L.username}</th><th>${L.mobile}</th><th>${L.email}</th><th>${L.regip}</th><th>${L.regdate}</th><th>${L.lastlogin}</th><th>${L.lastip}</th><th>${L.fromapp}</th><th>状态</th><th>${L.operation}</th>
								  </tr>
                                </thead>
                                <tbody>
								<%for(list in lists){%>
                                  <tr uid="${list.uid!0}">
                                    <td>${list.uid!0}</td><td>${list.username!}</td><td>${list.mobile!}</td>
									<td align="center">${list.email!}</td><td>${list.regip!0,ipFormat}</td><td>${list.regdate!0,timeFormat}</td><td>${list.lastlogintime!0,timeFormat}</td><td>${list.lastloginip!0,ipFormat}</td><td>${list.appname!}</td>
									<td align="center"><input type="checkbox" name="switch"  lay-text="正常|禁用" <%if(list.status=='1'){%> checked=""<%}%> lay-skin="switch" lay-filter="status" data-v="${list.status!0}"/></td>
                                    <td class="td-manage">
                                        <a title="编辑"  onclick="Sca.open('编辑','${'/admin/members/edit/uid/'+list.uid,url}',600,420)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                      </a>
                                      <a title="删除" onclick="record_del(this,'${list.uid!0}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>
                                      </a>
                                    </td>
                                  </tr>
								  <%}%>
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                <div>
                                  <a href="${'/admin/members/index'+params+'/page/1',url}">${L.firstpage}</a> 
                                   <%for(var i=pageinfo.s;i<=pageinfo.e;i++){
									  if(i==pageinfo.page){
									%>
									 <span class="current">${i}</span>
								     <%}else{%>
                                     <a href="${'/admin/members/index'+params+'/page/'+i,url}">${i}</a> 
                                   <%}}%>
                                  <a href="${'/admin/members/index'+params+'/page/'+pageinfo.pages,url}">${L.lastpage}</a> 
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
<% include("../public/commonfooter.html"){}%>
<script>
      layui.use(['laydate','form'], function(){
	    $ = layui.jquery;
        var laydate = layui.laydate;
        var  form = layui.form;
       

        // 监听全选
        form.on('checkbox(checkall)', function(data){

          if(data.elem.checked){
            $('tbody input[name="id"]').prop('checked',true);
          }else{
            $('tbody input[name="id"]').prop('checked',false);
          }
          form.render('checkbox');
        }); 
        
       form.on("switch(status)",function(data)
			{ let ov=parseInt($(this).data("v"));
			  let uid=parseInt($(this).parent().parent().attr("uid"));
			  let v=Math.abs(1-ov);
			  let that=$(this);
				$.post(jkas.url("/admin/members/setstatus"),{uid:uid,status:v},function(result)
				{if(200==result.code)
				    {that.data("v",v);
					}
					else
					{layer.msg('状态变更出错!',{icon:5,time:1000});
					 that.prop('checked',ov==1);
					 form.render('checkbox');
					}
				},"json");
				
               
			});


      });

/*用户-删除*/
      function record_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
         $.post(jkas.url("/admin/members/drop"),{uid:id},function(result)
			  {  if(200==result.code)
			     {
				  $(obj).parents("tr").remove();
                  layer.msg('已删除!',{icon:1,time:1000});
				  }
				  else
				  {layer.msg('删除出错!',{icon:5,time:1000});
				  }
			  },"json");
              
          });
      }



      function delAll (argument) {
        var ids = [];

        // 获取选中的id 
        $('tbody input[name="id"]').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
  
        layer.confirm('确认要删除所选吗？',function(index){
            //捉到所有被选中的，发异步进行删除
			$.post(jkas.url("/admin/members/drop"),{uids:ids.toString()},function(result)
			  {  if(200==result.code)
			     {
                    layer.msg('删除成功', {icon: 1});
                    $(".layui-form-checked").not('.header').parents('tr').remove();
				 }
				  else
				  {layer.msg('删除出错!',{icon:5,time:1000});
				  }
			  },"json");
        });
      }
</script>